﻿Imports System.Net
Imports System.Web.Http
Imports System.Net.Http
Imports Models.Solution
Imports Services.MapServices

Namespace Controllers

    Public Class LayerLibraryController
        Inherits ApiController

        ''' <summary>
        ''' Get LayerLibrary By Id
        ''' </summary>
        ''' <param name="id"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <AcceptVerbs("GET")> _
        Public Function [Get](id As Integer) As LayerLibraryVO
            Try
                Dim oService As New LayerLibraries(Request)
                Dim oEntity As LayerLibraryVO = oService.Get(id)
                Return oEntity
            Catch ex As Exception
                apiHelpers.ManageException(ex)
            End Try
        End Function

        ''' <summary>
        ''' Get LayerLibrary Content By Id
        ''' </summary>
        ''' <param name="id"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <AcceptVerbs("GET")> _
        Public Function GetContent(id As Integer) As HttpResponseMessage
            Try
                Dim oService As New LayerLibraries(Request)

                Dim res As New HttpResponseMessage()
                res.Content = New StringContent(oService.GetContent(id), System.Text.Encoding.UTF8, "application/xml")

                Return res

            Catch ex As Exception
                apiHelpers.ManageException(ex)
            End Try
        End Function

        ''' <summary>
        ''' Get List of LayerLibrary
        ''' </summary>
        ''' <returns>Array of LayerLibrary</returns>
        <AcceptVerbs("GET")> _
        Public Function List() As IEnumerable(Of LayerLibraryVO)
            Try
                Dim oService As New LayerLibraries(Request)
                Return oService.List()
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return Nothing
            End Try
        End Function

        ''' <summary>
        ''' Create a LayerLibrary
        ''' </summary>
        ''' <param name="layerlibrary"></param>
        ''' <returns>The new ID  of the entity</returns>
        ''' <remarks></remarks>
        <AcceptVerbs("POST")> _
        Public Function Create(layerLibrary As LayerLibraryVO) As Integer
            Try
                Dim oService As New LayerLibraries(Request)
                Return oService.Create(layerLibrary)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return -1
            End Try
        End Function

        ''' <summary>
        ''' Delete a LayerLibrary
        ''' </summary>
        ''' <param name="id">LayerLibraryId</param>
        ''' <returns>1 if OK</returns>
        ''' <remarks></remarks>
        <AcceptVerbs("DELETE")>
        Public Function Delete(id As Integer) As Integer
            Try
                Dim oService As New LayerLibraries(Request)
                Return oService.Delete(id)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return -1
            End Try
        End Function

    End Class

End Namespace